package com.itheima.edu.info.manage.service;

import com.itheima.edu.info.manage.dao.studentDao;
import com.itheima.edu.info.manage.domain.student;

public class studentService {
    private studentDao studentDao = new studentDao();
    public boolean addstudent(student stu) {

        return studentDao.addstudent(stu);

    }

    public boolean isExist(String id) {
        //studentDao studentDao = new studentDao();
        student[] stus = studentDao.findAllstudent();
        boolean exists = false;
        for (int i = 0; i < stus.length; i++) {
            student student = stus[i];
            if (student != null && student.getSid().equals(id)) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    public student[] findAllstudent() {
        student[] allstudent = studentDao.findAllstudent();
        boolean flag=false;
        for (int i = 0; i < allstudent.length; i++) {
            student stu = allstudent[i];
            if(stu!=null){
                flag=true;
                break;
            }
        }
        if(flag){
            return allstudent;
        }else {
            return null;
        }

    }

    public void deletestudentByid(String delid) {
        studentDao.deletestudentByid(delid);
    }

    public void updatestudent(String updateid, student newstu) {
        studentDao.updatestudent(updateid,newstu);
    }
}
